package benny_driving_ser.util;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.MalformedURLException;
import java.net.URL;

public class HttpConUrlUtil {
	
	/**
	 * java代码访问url
	 */
	public static String UrlCon(){
		
		String httpUrl = "http://localhost:8080/benny_driving/servlet/LoginServlet?action=dri-login&acc=wulili1&psd=123456";
		//String httpUrl="http://mydns2.xinnet.com/"+"cgi-bin/dnsapi_add?+name=" + mainDomain + "&recordname=" + webServer+ "&type=CNAME&content=" + domain + "&ttl=3600&prio=5";
		URL url;
		try {
			url = new URL(httpUrl);
			HttpURLConnection httpUrlCon = (HttpURLConnection) url
					.openConnection();
			httpUrlCon.setDoOutput(true);
			httpUrlCon.setRequestMethod("GET");
			BufferedReader xinnetIn = new BufferedReader(new InputStreamReader(
					httpUrlCon.getInputStream()));
			String back = xinnetIn.readLine();
			if(null != back && back.contains("ret=100")) {
				System.out.println(back);
//				log.debug(" zhixiang successfully!");
			}
			xinnetIn.close();
			httpUrlCon.disconnect();
			return "发送消息成功...";
		} catch (MalformedURLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (IOException e){
			e.printStackTrace();
		}
		
//		else {
////			log.debug("connect error  sitebuild zhixiang error!");
//			System.out.println("网络错误，请重试");
//			put("error","网络错误，请重试");
////			throw new ("自助建站开通成功，指向错误！");
//		}
		
		return null;
	}
	
	
	public static void main(String[] args) {
		System.out.println(UrlCon());
	}
}
